// pages/my/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headImg:'',
    name:'05',
    officeName:'',
    duty:''

  },
  out: function () {
    app.thirdScript.http.post('app/user/logout', { loginName: wx.getStorageSync('userInfo').phone }, 'getLogout', this);
  },
  getLogout:function(res){
    if(res.code == 200){
      wx.showToast({
        title: res.message,
      })
      wx.clearStorage()
      wx.reLaunch({
        url: '../login/login'
      })
    }
  },
  
  modify: function (e) {
    var _this = this;
    wx.chooseImage({
      count: 1,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        const tempFilePaths = res.tempFilePaths
        wx.uploadFile({
          url: 'https://zdxm.zhyaohai.com/qianmi-wisdom-zdxm-web-api/app/user/resetHP', 
          filePath: tempFilePaths[0],
          name: 'file',
          formData: {
            'appUserId': wx.getStorageSync('userInfo').id
          },
          success(res) {
            if(res.code == 200){
              wx.showToast({
                title: res.message
              })
            }
          }
        })
        _this.setData({
          headImg: res.tempFilePaths
        })
      }
    })
  },
  updateHeadIcon: function(res){
    if(res.code == 200){
      var _userInfo = wx.getStorageSync('userInfo');
      _userInfo.photo = res.data.file;
      wx.setStorageSync('userInfo', _userInfo);
      wx.showToast({
        title: res.message,
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.thirdScript.http.post('app/user/personal', { appUserId: wx.getStorageSync('userInfo').id }, 'getUserinfo', this); 
  },
  getUserinfo: function(res){
    if(res.code == 200){
      this.setData({
        headImg: 'http://36.33.216.250:9003/qianmi-wisdom-zdxm-web-api/zdxm/file/'+res.content.photo,
        name: res.content.name,
        officeName: res.content.officeName,
        duty: res.content.duty
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})